package com.example.demo.service.impl;

import com.example.demo.dao.ClassificationTableDao;
import com.example.demo.dao.CommodityListDao;
import com.example.demo.dao.PictureSheetOfMerchandiseDao;
import com.example.demo.pojo.ClassificationTable;
import com.example.demo.pojo.CommodityList;
import com.example.demo.pojo.PictureSheetOfMerchandise;
import com.example.demo.service.GoodsUplond;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GoodsUplondImpl implements GoodsUplond {
    @Autowired
    CommodityListDao commodityListDao;

    @Autowired
    PictureSheetOfMerchandiseDao pictureSheetOfMerchandiseDao;


    @Autowired
    ClassificationTableDao classificationTableDao;





    //增加商品内容
    @Override
    public int addGoods(CommodityList commodityList) {
     return  commodityListDao.insert(commodityList);
    }


    //依据商品sku码找到商品id
    @Override
    public int findGoodsId(String sku) {
        return commodityListDao.findIdbySkucode(sku);
    }

    //增加商品图片路径
    @Override
    public int addGoodsPath(PictureSheetOfMerchandise pictureSheetOfMerchandise) {
        return pictureSheetOfMerchandiseDao.insert(pictureSheetOfMerchandise);

    }
    //首次查找分类
    @Override
    public Map<String,List<ClassificationTable>> firstFindClassfication() {
        Map<String,List<ClassificationTable>> map=new HashMap<>();
        //获取一级分类
        List<ClassificationTable> list =classificationTableDao.findClassficationtableByPid(0);
        map.put("fristClassify",list);
        //获取第一个一级分类id
        ClassificationTable classificationTable=list.get(0);
        int first=classificationTable.getClassificationid();
        //获取二级分类id
        List<ClassificationTable> list1 =classificationTableDao.findClassficationtableByPid(first);
        map.put("secondClassify",list1);
        return map;
    }

    @Override
    public int addGoodsOfReadis() {
        return 0;
    }

    @Override
    public int addGoodsOfSlor() {
        return 0;
    }
}
